/***********************************************************************************
*	File: Kunai.cpp
*	Author: Keisuke Miyazaki
*	Project: Mari's Flower
*	Date: 09/27/2013
***********************************************************************************/
#include "Kunai.h"
#include "../GameStates/GamePlayState.h"

#include "../Messages and Events/DestroyEntityMessage.h"

#include "../../SGD Wrappers/CSGD_Direct3D.h"
#include "../../SGD Wrappers/CSGD_DirectInput.h"
#include "../../SGD Wrappers/CSGD_TextureManager.h"
#include "../../SGD Wrappers/CSGD_MessageSystem.h"

#define TM CSGD_TextureManager::GetInstance()
#define D3 CSGD_Direct3D::GetInstance()

CKunai::CKunai(int owner)
{
	switch ( owner )
	{
	case 0:
		{
			m_eType			=	ENT_KUNAI;
		}
		break;
	case 1:
		{
			m_eType			=	ENT_E_KUNAI;
		}
		break;
	}
	
}

void CKunai::Update( float fElapsedTime )
{
	CGamePlayState* pGPS = CGamePlayState::GetInstance();
	RECT rTemp		= {};
	RECT rSelf		= GetRect();
	RECT rScreen	= 
	{
		( LONG ) 0,
		( LONG ) 0,
		( LONG ) 1024,
		( LONG ) 1024
	};

	if( IntersectRect( &rTemp, &rSelf, &rScreen ) == FALSE )
	{
		CDestroyEntityMessage* pMsg = new CDestroyEntityMessage( this );

		CSGD_MessageSystem::GetInstance()->SendMsg( pMsg );
		pMsg = nullptr;
	}

	CEntity::Update( fElapsedTime );
}

void CKunai::Render( void )
{
	CGamePlayState*			pGame	= CGamePlayState::GetInstance();
	CSGD_Direct3D*			pD3		= CSGD_Direct3D::GetInstance();
	CSGD_TextureManager*	pTM		= CSGD_TextureManager::GetInstance();

	pTM->Draw( GetImageID(), 
		(int)(GetPosX() - pGame->GetCameraX()), 
		(int)(GetPosY() - pGame->GetCameraY()), 
		GetScaleX(), GetScaleY(), nullptr,
		GetWidth() * 0.5f, 
		GetHeight() * 0.5f,
		GetRotation());
}
void CKunai::HandleCollision( const IEntity* pOther )
{
	switch ( pOther->GetType() )
	{
	case ENT_PLAYER:
	case ENT_ENEMY:
		{
			CDestroyEntityMessage* pMsg = new CDestroyEntityMessage( this );

			CSGD_MessageSystem::GetInstance()->SendMsg( pMsg );
			pMsg = nullptr;
		}
		break;
	}
}